<?php
class View_Administration_User_List extends View_Administration_User
{
	/**
	 *	Builds edit User View.
	 *	@access		private
	 *	@return		string
	 */
	public function buildContent()
	{
		$config		= $this->registry->get( 'config' );
		$request	= $this->registry->get( 'request' );
		$session	= $this->registry->get( 'session' );
		$auth		= $this->registry->get( 'auth' );
		$words		= $this->words['user']['listUsers'];

		$options	= array(
			'coverage'		=> $config['layout.list_coverage'],
			'key_offset'	=> "offset",
		);
		$heads	= array(
			$words['head_title'],
			$words['head_roles'],
			$words['head_status'],
			$words['head_info'],
		);

		$actions	= array();
		$list	= new CMF_Krypton_View_Component_List( 'Collection_User' );
		$list->setActionForm( 'listUsers' );
		$list->setActions( $actions );
		$list->setCaption( $words['caption'] );
		$list->setColumnGroup( $words['colgroup'] );
		$list->setTemplates( 'administration.user.list', 'administration.user.listitem', 'paging' );
		$list->setLimitKey( 'administration_users_limit' );
		$list->setOffsetKey( 'administration_users_offset' );
		$list->setHeads( $heads );
		$list->setPagingOptions( $options );
		$list->setTransformer( $this, 'transformListEntry' );

		$list->collectUsers();
		if( $session->get( 'administration_users_order' ) )
			$list->orderBy( $session->get( 'administration_users_order' ), $session->get( 'administration_users_direction' ) );
		if( $session->get( 'administration_users_username' ) )
			$list->withUsernameLike( $session->get( 'administration_users_username' ) );
		if( $session->get( 'administration_users_email' ) )
			$list->withEmailLike( $session->get( 'administration_users_email' ) );
		$list	= $list->getList();

		$ui['list']		= $list;
		$ui['heading']	= $words['heading'];
		$ui['link_add']	= $this->html->LinkButton( "?link=".$request->get( 'link' )."&add", $words['link_add'], 'but add' );
		return $this->loadTemplate( 'administration.user.users', $ui );
	}

	public function transformListEntry( $entry )
	{
		$config		= $this->registry->get( 'config' );
		$request	= $this->registry->get( 'request' );
		$words		= $this->words['user']['listUsers'];
		$logic		= new Logic_User();
		$path		= $config['paths.icon.lib']."famfamfam/silk/";

		$item['link']		= $this->html->Link( "?link=".$request->get( 'link' )."&userId=".$entry['userId'], $entry['username'] );
		$item['logged']		= $entry['logged'] ? $this->html->Image( $path."key.png", $words['icon_logged']." ".$this->tc->convertToHuman( $entry['logged'], "datetime" ) ) : "";
		$item['status']		= $this->getStatusIcon( $entry['status'], $words['icon_status'] );
		$list	= array();
		$roles	= Logic_Role::getUserRoles( FALSE, $entry['userId'] );
		foreach( $roles as $roleId => $roleTitle )
			$list[]	= $this->html->Link( "?link=roles&roleId=".$roleId, $roleTitle );
		$item['roles']	= implode( ", ", $list );
		return $item;
	}
}
?>